﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CloudDcPc
{
    /// <summary>
    /// PrintTest1.xaml 的交互逻辑
    /// </summary>
    public partial class PrintTest1 : Window
    {
        public PrintTest1()
        {
            InitializeComponent();
        }
        StreamReader streamToPrint = null;
        Font printFont;

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            printFont = new Font("宋体", 10f, System.Drawing.FontStyle.Underline);
            PrintDocument pd = new PrintDocument();
            pd.PrintController = new System.Drawing.Printing.StandardPrintController();    //取消打印页码显示对话框！ 

            pd.PrintPage += pd_PrintPage;
            pd.EndPrint += pd_EndPrint;

            pd.DefaultPageSettings.Margins.Top = 2;
            pd.DefaultPageSettings.Margins.Left = 12;
            //pd.DefaultPageSettings.PaperSize.Width = 346;
            //pd.DefaultPageSettings.PaperSize.Height = 5150;

            pd.PrinterSettings.PrinterName = "XP-80";
            //pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
            pd.Print();


        }

        void pd_EndPrint(object sender, PrintEventArgs e)
        {
            if (streamToPrint != null)
                streamToPrint.Close();//释放不用的资源
        }

        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {

            float leftMargin = e.MarginBounds.Left-10;//左边距
            float topMargin = e.MarginBounds.Top;//顶边距

            //yPos = topMargin + (count * printFont.GetHeight(e.Graphics));

            e.Graphics.DrawString("方法第三方第三方fadasfsfsadfs\ndsfsdaf\nesfe\n", printFont, System.Drawing.Brushes.Black,
            leftMargin, 0, new StringFormat());//打印，参见第五章

        }



    }
}
